//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "GaussJacobiIntegration.h"
using namespace Cephei::QL::Math::Integrals;
#include <gen/QL/Math/Integrals/GaussianOrthogonalPolynomial.h>
#include <gen/QL/Math/Integrals/GaussianQuadrature.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CGaussJacobiIntegration::CGaussJacobiIntegration (UInt64 n, Double alpha, Double beta) : CGaussianQuadrature(CGaussJacobiIntegration::typeid)
{
    try
    {
#ifdef HANDLE
        _phGaussJacobiIntegration = NULL;
#endif
        QuantLib::Size _n = (QuantLib::Size)ValueHelper::Convert (n);
        QuantLib::Real _alpha = (QuantLib::Real)ValueHelper::Convert (alpha);
        QuantLib::Real _beta = (QuantLib::Real)ValueHelper::Convert (beta);
        _ppGaussJacobiIntegration = new boost::shared_ptr<QuantLib::GaussJacobiIntegration> (new QuantLib::GaussJacobiIntegration ( _n,  _alpha,  _beta ));
        SetGaussianQuadrature (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussJacobiIntegration));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::CGaussJacobiIntegration::CGaussJacobiIntegration (boost::shared_ptr<QuantLib::GaussJacobiIntegration>& childNative, Object^ owner) : CGaussianQuadrature(CGaussJacobiIntegration::typeid)
{
#ifdef HANDLE
	_phGaussJacobiIntegration = NULL;
#endif
	_ppGaussJacobiIntegration = &childNative;
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussJacobiIntegration));
}
Cephei::QL::Math::Integrals::CGaussJacobiIntegration::CGaussJacobiIntegration (QuantLib::GaussJacobiIntegration& childNative, Object^ owner) : CGaussianQuadrature(CGaussJacobiIntegration::typeid)
{
#ifdef HANDLE
	_phGaussJacobiIntegration = NULL;
#endif
	_ppGaussJacobiIntegration = new boost::shared_ptr<QuantLib::GaussJacobiIntegration> (&childNative);
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussJacobiIntegration));
    _GaussJacobiIntegrationOwner = owner;
    _GaussianQuadratureOwner = owner;
}

Cephei::QL::Math::Integrals::CGaussJacobiIntegration::CGaussJacobiIntegration (CGaussJacobiIntegration^ copy) : CGaussianQuadrature(CGaussJacobiIntegration::typeid)
{
#ifdef HANDLE
	_phGaussJacobiIntegration = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGaussJacobiIntegration = new boost::shared_ptr<QuantLib::GaussJacobiIntegration> (copy->GetShared());
        _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussJacobiIntegration));
    }
}
Cephei::QL::Math::Integrals::CGaussJacobiIntegration::CGaussJacobiIntegration (System::Type^ t) : CGaussianQuadrature(CGaussJacobiIntegration::typeid)
{
#ifdef HANDLE
	_phGaussJacobiIntegration = NULL;
#endif
	if (!t->IsSubclassOf(CGaussJacobiIntegration::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CGaussJacobiIntegration::CGaussJacobiIntegration (QuantLib::Handle<QuantLib::GaussJacobiIntegration>& childNative, Object^ owner)  : CGaussianQuadrature(CGaussJacobiIntegration::typeid)
{
	_phGaussJacobiIntegration = &childNative;
	_ppGaussJacobiIntegration = &static_cast<boost::shared_ptr<QuantLib::GaussJacobiIntegration>>(childNative.currentLink());
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussJacobiIntegration));
    _GaussJacobiIntegrationOwner = owner;
}
Cephei::QL::Math::Integrals::CGaussJacobiIntegration::CGaussJacobiIntegration (QuantLib::Handle<QuantLib::GaussJacobiIntegration> childNative)  : CGaussianQuadrature(CGaussJacobiIntegration::typeid)
{
	_phGaussJacobiIntegration = &childNative;
	_ppGaussJacobiIntegration = &static_cast<boost::shared_ptr<QuantLib::GaussJacobiIntegration>>(childNative.currentLink());
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussJacobiIntegration));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CGaussJacobiIntegration::CGaussJacobiIntegration (QuantLib::GaussJacobiIntegration childNative)  : CGaussianQuadrature(CGaussJacobiIntegration::typeid)
{
#ifdef HANDLE
	_phGaussJacobiIntegration = NULL;
#endif
	_ppGaussJacobiIntegration = new boost::shared_ptr<QuantLib::GaussJacobiIntegration> (new QuantLib::GaussJacobiIntegration (childNative));
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussJacobiIntegration));
}
#endif

Cephei::QL::Math::Integrals::CGaussJacobiIntegration::~CGaussJacobiIntegration ()
{
    if (_ppGaussJacobiIntegration != NULL)
    {
	    delete _ppGaussJacobiIntegration;
        _ppGaussJacobiIntegration = NULL;
    }
}
Cephei::QL::Math::Integrals::CGaussJacobiIntegration::!CGaussJacobiIntegration ()
{
    if (_ppGaussJacobiIntegration != NULL)
    {
	    delete _ppGaussJacobiIntegration;
    }
}
QuantLib::GaussJacobiIntegration& Cephei::QL::Math::Integrals::CGaussJacobiIntegration::GetReference ()
{
    if (_ppGaussJacobiIntegration == NULL) throw gcnew NativeNullException ();
	return **_ppGaussJacobiIntegration;
}
boost::shared_ptr<QuantLib::GaussJacobiIntegration>& Cephei::QL::Math::Integrals::CGaussJacobiIntegration::GetShared ()
{
    if (_ppGaussJacobiIntegration == NULL) throw gcnew NativeNullException ();
	return *_ppGaussJacobiIntegration;
}
QuantLib::GaussJacobiIntegration* Cephei::QL::Math::Integrals::CGaussJacobiIntegration::GetPointer ()
{
    if (_ppGaussJacobiIntegration == NULL) throw gcnew NativeNullException ();
	return &**_ppGaussJacobiIntegration;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GaussJacobiIntegration>& Cephei::QL::Math::Integrals::CGaussJacobiIntegration::GetHandle ()
{
	if (_phGaussJacobiIntegration == NULL)
	{
		_phGaussJacobiIntegration = new Handle<QuantLib::GaussJacobiIntegration> (*_ppGaussJacobiIntegration);
	}
	return *_phGaussJacobiIntegration;
}
#endif
bool Cephei::QL::Math::Integrals::CGaussJacobiIntegration::HasNative () 
{
	return (_ppGaussJacobiIntegration != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Integrals::IGaussJacobiIntegration^ Cephei::QL::Math::Integrals::CGaussJacobiIntegration_Factory::Create (UInt64 n, Double alpha, Double beta)
{
    return gcnew CGaussJacobiIntegration ( n,  alpha,  beta);
}
